##### define Toolchain version
TOOLCHAIN_VERSION = V1.90
##### define compiler prefix
# need add Toolchain Path to PATH 
CROSS_COMPILER_PREFIX = riscv-none-embed-
# or use this, complete full path of Toolchain
#CROSS_COMPILER_PREFIX = $(HOME)/wch32v/wch-package/MRS_Toolchain_Linux_x64_$(TOOLCHAIN_VERSION)/RISC-V Embedded GCC/bin/riscv-none-embed-
#CROSS_COMPILER_PREFIX = C:/MounRiver/MounRiver_Studio/toolchain/RISC-V Embedded GCC/bin/riscv-none-embed-

##########################################################

#OPENOCD = C:/MounRiver/MounRiver_Studio/toolchain/OpenOCD/bin/openocd.exe
#OPENOCD_ARGS = -f C:/MounRiver/MounRiver_Studio/toolchain/OpenOCD/bin/wch-riscv.cfg

#OPENOCD = $(HOME)/MRS_Toolchain_Linux_x64_V1.80/OpenOCD/bin/openocd
#OPENOCD_ARGS = -f $(HOME)/MRS_Toolchain_Linux_x64_V1.80/OpenOCD/bin/wch-riscv.cfg

##### debug tool 
OPENOCD = $(HOME)/wch32v/wch-package/MRS_Toolchain_Linux_x64_$(TOOLCHAIN_VERSION)/OpenOCD/bin/openocd 
OPENOCD_ARGS = -f $(HOME)/wch32v/wch-package/MRS_Toolchain_Linux_x64_$(TOOLCHAIN_VERSION)/OpenOCD/bin/wch-riscv.cfg

##### 
# OPENOCD = openocd
#OPENOCD = /usr/local/bin/openocd
# OPENOCD_ARGS = -f $(HOME)/wch32v/openocd-hacks/tcl/interface/wlink.cfg -f $(HOME)/wch32v/openocd-hacks/tcl/target/wch-riscv.cfg

##### gcc argument
##### 
#ARCH = -march=rv32imafc -mabi=ilp32f

#ARCH = -march=rv32imac -mabi=ilp32

ARCH = -march=rv32ec -mabi=ilp32e

CH32_WORKSPACE_DIR = $(wildcard $(HOME)/wch32v/workspace)
##### Source Code
CH32_STD_LIB_DIR = $(wildcard $(CH32_WORKSPACE_DIR)/ch32-standard-library/ch32v00x)

CH32_DEBUG_LIB_DIR = $(wildcard $(CH32_STD_LIB_DIR)/sample)

#### Current Project
CH32_PROJECT_DIR	= $(wildcard $(CH32_WORKSPACE_DIR)/ch32v003-demo)

CROSS_C_SOURCE_FILES += $(wildcard $(CH32_STD_LIB_DIR)/peripheral/src/*.c)
CROSS_C_SOURCE_FILES += $(wildcard $(CH32_STD_LIB_DIR)/core/*.c)
CROSS_C_SOURCE_FILES += $(wildcard $(CH32_DEBUG_LIB_DIR)/*.c)
CROSS_C_SOURCE_FILES += $(wildcard $(CH32_PROJECT_DIR)/src/*.c)

##### start file
CROSS_ASM_SOURCE_FILES += $(CH32_STD_LIB_DIR)/sample/startup.S

##### gcc compiler optimition
CROSS_C_FLAGS += -fno-common -fno-builtin -Os

##### Project predefine ---- for ch32-std-lib
CROSS_C_FLAGS += -DCHIP_CH32V00X

#CROSS_C_FLAGS += -DBEZIER_DEBUG
#ld flags & ld file
CROSS_LD_FLAGS += -Wl,--no-relax -specs=nosys.specs -specs=nano.specs -nostartfiles \
-T$(CH32_STD_LIB_DIR)/sample/default.ld

#ld library
# CROSS_LD_FLAGS += -lm

##### include file path
CROSS_C_INCLUDES += $(CH32_STD_LIB_DIR)/peripheral/inc \
					$(CH32_STD_LIB_DIR)/core \
					$(CH32_DEBUG_LIB_DIR) \
					$(CH32_PROJECT_DIR)/src \


OPENOCD_FLASH_COMMANDS = -c "program $< verify" -c wlink_reset_resume -c exit

include ./miscellaneous-makefiles/cross-gcc-mcu.mk

